package com.lanou.dllo.baisibudejie.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.SparseArray;

/**
 * Created by dllo on 15/10/22.
 */
public class CardFragmentFactory extends Fragment {

    //    private static Map<Integer, Fragment> fragmentMap = new HashMap<>();
    private static SparseArray<Fragment> fragmentSparseArray = new SparseArray<>();

    public  static Fragment createFragment(int position){

        Fragment f = fragmentSparseArray.get(position);
        if ((f == null)) {
            switch (position) {
                case 0:
                    f = new JokesFragment();
                    break;
                case 1:
                    f = new ImagesFragment();
                    break;
                default:
                    f = new MusicFragment();
                    break;
            }
            Bundle bundle_jokes = new Bundle();
            bundle_jokes.putInt("position", position);
            f.setArguments(bundle_jokes);
            fragmentSparseArray.put(position,f);
        }

        return f;
    }

}
